package com.jomoo.scs.controller.userinfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.jomoo.scs.config.AppContext;
import com.jomoo.scs.dto.user.AccountDto;
import com.jomoo.scs.model.user.WechatAuthenticationResponse;
import com.jomoo.scs.service.user.UserService;
import com.jomoo.scs.utils.ResultBean;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api("用户信息相关接口")
@RestController
@RequestMapping("/user")
public class UserInfoController {

	@Autowired
	private UserService userService;

	    @PostMapping("/test")
	    public String test() {
	        return "test_success";
	    }

	    @PostMapping("/testAuth")
	    public String testAuth() {
	        return "testAuth_success";
	    }

	    @ApiOperation(value="获取授权微信的openId", notes="传入code获取授权微信的openId")
		@ApiImplicitParams(
		{@ApiImplicitParam(name = "code", value = "微信接口返回code", required = true, dataType = "String")})
		@RequestMapping(path="/auth",method=RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	    public ResultBean createAuthenticationToken(@RequestBody AccountDto accountDto){
	        WechatAuthenticationResponse jwtResponse = userService.wechatLogin(accountDto.getCode());
	        return ResultBean.success(jwtResponse);
	    }
	    
	    
	    @ApiOperation(value="发送短信", notes="发送短信绑定用户账号")
		@ApiImplicitParams(
		{@ApiImplicitParam(name = "phone", value = "手机号", required = true, dataType = "String")})
		@RequestMapping(path="/sendMessage",method=RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	    public ResultBean sendMessage(@RequestBody AccountDto accountDto){
	    	String openId = AppContext.getCurrentUserWechatOpenId();
	       System.out.println("登录用户的openID为："+openId);
	        return ResultBean.success("ok");
	    }
	    
	    
	    

	   
}
